const promiseAll = function(ajaxArr, func, hideLoading){
	if (!ajaxArr) {
		return false
	}
	let pages = getCurrentPages();
	let _that = pages[pages.length - 1];
	let arr = []
	ajaxArr.forEach(e=>{
		arr.push(_that.om.request(e.url, e.param || {}, e.method || "", true))
	})
	//多个AJAX全部完成时开始执行
	if(!hideLoading){
		uni.showLoading({
			mask: true,
			title: '请稍候...'
		})
	}
	Promise.all(arr).then(res => {
		if(!hideLoading){
			uni.hideLoading()
		}
		func(res)
	})
}

const promise = function(urlObj, func){
	if (!urlObj) {
		return false
	}
	let pages = getCurrentPages();
	let _that = pages[pages.length - 1];
	_that.om.request(urlObj.url, urlObj.param || {}, urlObj.method || "").then(res=>{
		func(res)
	})
}

/**
 * 获取表单模板
 * @param {String} busCode 表单编码
 */
const tableModelUrl = function(busCode){
	return {
		url:"formFieldConfig/showPage",
		param:{
			code:busCode
		}
	}
}

/**
 * 用户相关数据字典下拉框
 * @param {Object} code
 */
const sysdictComboboxUrl = function(code){
	return {
		url:"tsysdict/getCombobox",
		param:{
			code:code
		},
		namefield:"dicname"
	}
}

/**
 * 用户无关数据字典下拉框
 * @param {Object} code
 */
const dictZeroComboboxUrl = function(code){
	return {
		url:"dictZero/getListByCode",
		param:{
			code:code
		},
		namefield:"dicname"
	}
}

const dictZeroComboboxUrlByInCode = function(code="",inCode=[]){
	return {
		url:"dictZero/getListByCode",
		param:{
			code:code,
			inCode:inCode
		},
		namefield:"dicname"
	}
}

/**
 * 获取管控参数初始值
 * @param {Object} code 要查找数据的编码
 */
const dataDictInitValueUrl = function(code){
	return {
		url:"dataDict/getIntByCode",
		param:{
			code:code
		}
	}
}

/**
 * 管控参数下拉框
 * @param {Object} code 父类code
 */
const dataDictComboboxUrl = function(code){
	return {
		url:"dataDict/getCombobox",
		param:{
			code:code
		},
		namefield:"dicname"
	}
}

/**
 * 制表岗位下拉框
 * @param {Object} code
 */
const zposUrl = function(busCode){
	return {
		url:"wxPosBusiAuth/isnewList",
		param:{
			code:busCode
		},
		method:"post",
		namefield:"posName"
	}
}

/**
 * 员工分页查询，跳转页
 * 只显示计酬岗位
 */
const userPageUrl = function(){
	return {
		url:"temployee/getStaffCombogrid",
		prompt:"请输入姓名、手机号、岗位、机构",
		namefield:"userPosInstName"
	}
}

/**
 * 任职记录分页查询，跳转页
 */
const officePageUrl = function(){
	return {
		url:"orgInstPosUserOfficial/findPagerByOrgId",
		prompt:"请输入姓名、岗位、机构",
		namefield:"userPosInstName"
	}
}

/**
 * 获取员工的所有任职岗位列表
 * @param {Object} userId 员工ID
 */
const posByUserComboboxUrl = function(userId){
	return {
		url:"orgInstPosUserOfficial/getPostList",
		param:{
			'user.id':userId
		},
		namefield:"posname"
	}
}

const userByPosComboboxUrl = function(posId){
	return {
		url:"orgInstPosUserOfficial/getUserByPos",
		param:{
			posId:posId
		},
		namefield:"username"
	}
}

const userListByUserId = function(userId){
	return {
		url:"orgInstPosUserOfficial/findSameInstUserListByUserId",
		param:{
			userId:userId
		},
		method:"post",
		namefield:"username"
	}
}
const getMonthList = function(){
	return {
		url:"common/findMonthList",
		namefield:"dicname"
	}
}
const getYearList = function(){
	return {
		url:"common/findYearList",
		namefield:"dicname"
	}
}
/**
 * 地址
 * @param {Object} classifyCode 行政区划分类（省、市、区对应的数据字典（DictZero）编码）
 */
const addressUrl = function(classifyCode){
	return {
		url:"regions/getAddressCombox",
		param:{
			classifyCode:classifyCode
		},
		namefield:"fullName"
	}
}

const findEmployee = function(){
	return {
		url:"temployee/findAllEmployee",
		namefield:"username",
		notefield:"sexName",
		extrafield:"subMobile"
	}
}
const getInstList = function(){
	return {
		url:"tinstitution/findNotBoard1",
		namefield:"instName",
		prompt:"请输入机构名称"
	}
}
/*
	获取同部门员工
*/
const findUserAsSameInst = function(){
	return {
		url:"orgInstPosUserOfficial/findUserAsSameInst",
		namefield:"userSalaryPosInstName",
		extrafield:"salaryPosInstName",
	}
}

export {
	tableModelUrl,
	sysdictComboboxUrl,
	dictZeroComboboxUrl,
	zposUrl,
	userPageUrl,
	officePageUrl,
	dataDictInitValueUrl,
	dataDictComboboxUrl,
	posByUserComboboxUrl,
	userByPosComboboxUrl,
	addressUrl,
	promiseAll,
	promise,
	dictZeroComboboxUrlByInCode,
	userListByUserId,
	getYearList,
	getMonthList,
	findEmployee,
	getInstList,
	findUserAsSameInst
}